import QtQuick 2.12
import QtQuick.Controls 2.14
import QtGraphicalEffects 1.14

// 下拉列表样式
Item {

    id: root

    height: 40*dp
    width: parent.width
    property string title: "..."

    property bool isHovered: false      // 悬停
    property bool isChecked: false      // 选择

    // 背景颜色
    property color background_color: "white"
    property color background_color_hover: config.themeColor_light2
    property color background_color_checked: "white"

    // 文字颜色
    property color text_color: "#333333"
    property color text_color_hover: config.themeColor_deep
    property color text_color_checked: config.themeColor_deep

    // 图标标识(放在右侧)
    property real   indicator_size: 12*dp
    property string indicator: ""
    property string indicator_hovered: ""
    property string indicator_checked: "qrc:/picture/tick1_b.png"

    property real radius: 0

    signal clicked()

    Rectangle{
        id: rect_content
        anchors.fill: parent
        radius: root.radius
        color: isHovered ? background_color_hover : (isChecked ? background_color_checked : background_color)
        Text{
            text: title
            anchors.verticalCenter: parent.verticalCenter
            font.pixelSize: config.fontsize
            leftPadding: 10*dp
            color: isHovered ? text_color_hover : (isChecked ? text_color_checked : text_color)
        }
    }

//    MouseArea{
//        anchors.fill: rect_content

//        hoverEnabled: config.hoverEnabled
//        onEntered: {
//            isHovered = config.hoverEnabled
//        }onExited: {
//            isHovered = false
//        }onClicked: {
//            root.clicked()
//        }
//    }

    // indicator
    CustomImage{

        visible: {
            if(isChecked)   return indicator_checked !== ""
            if(isHovered)   return indicator_hovered !== ""
            return indicator !== ""
        }

        height: indicator_size; width: indicator_size
        x: parent.width - width - (parent.height-indicator_size) * 0.5
        y: (parent.height - indicator_size) * 0.5
        anchors.verticalCenter: parent.verticalCenter
        source: indicator_checked
    }

}
